/* rcslb03.p - CREATE STAGE LIST ENTRIES FOR SEQ. ORDER LINES               */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.                      */
/* $Revision: 1.17 $                                                             */
/*V8:ConvertMode=NoConvert                                                  */
/*V8:RunMode=Character,Windows                                              */
/* REVISION: 9.1           CREATED: 06/14/99    BY: *N003* Patrick Rowan    */
/* REVISION: 9.1     LAST MODIFIED: 08/12/00    BY: *N0KP* myb                       */
/* $Revision: 1.17 $       BY:Patrick Rowan    DATE:07/05/00        ECO:N0F6     */
/*!
 ----------------------------------------------------------------------------
 DESCRIPTION: Read the qad_wkfl for gross quantities and get the next
              sequences to match the quantities.  Save the sequences and
              their recid in the temp. table for later processing.

 Notes:
 ============================================================================
 !*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */

         {mfdeclre.i}

         /* PARAMETERS */
         define input parameter in_sod_nbr like sod_nbr no-undo.
         define input parameter in_sod_line like sod_line no-undo.
         define input parameter in_qad_wkfl_recid as recid no-undo.
         define input parameter in_all_only as logical no-undo.


         /* VARIABLES */
         define variable l_key1 like qad_key1 no-undo.
         define variable l_key2 like qad_key2 no-undo.
         define variable qad_recid as recid no-undo.
         define variable total_qty like sod_qty_ord no-undo.
         define variable shipfrom_date as date no-undo.
         define variable shipfrom_time as character no-undo.
         define variable arrive_date as date no-undo.
         define variable arrive_time as character no-undo.
         define variable ret_status as character no-undo.
         define variable translt_days like sod_translt_days no-undo.


         /* SHARED VARIABLES */
/*N0F6*/ define new shared variable l_inc_wkend_shpcal  like so_incl_iss
/*N0F6*/                                                no-undo.
         {sosqvars.i}




         /* INITIALIZATION */
         for first sod_det where
            sod_nbr     = in_sod_nbr    and
            sod_line    = in_sod_line
            no-lock: end.

         for first so_mstr where
            so_nbr  = sod_nbr
            no-lock: end.



         assign
            l_key1       = mfguser + global_db + "stage_list"
            l_key2       = sod_nbr + string(sod_line)
/*N0F6*/    l_inc_wkend_shpcal = so_incl_iss
            translt_days = dec(substr(so_conrep,2,6)).


         /* LEAVE IF NO SEQUENCES FOUND FOR THIS SHIPFROM/SHIPTO */
         for first rcs_mstr where
            rcs_shipfrom    = so_site   and
            rcs_shipto      = so_ship   and
            rcs_active no-lock: end.

         if not available (rcs_mstr) then
            leave.




         /* PROCESS ONLY THE WORK-FILE RECORDS THAT CONTAIN QUANTITIES */
         for each qad_wkfl where
            recid(qad_wkfl) = in_qad_wkfl_recid
            exclusive-lock:


            /* SKIP THE LINE IF ZERO QUANTITY AND PRINT-ALL-LINES */
            if qad_decfld[1] = 0 and not in_all_only then
                next.

            /* IS THE ORDER MARKED AS BEING 'SEQUENCED' ? */
            if so_seq_order then do:


                /* INSERT "1" TO MODIFY THE KEY & HELP_wkfl */
                /* SEQ. qad_wkfl with begin with "z". PURPOSE: SORTING   */
                qad_key2 = "1" + qad_key2.

                /* FIND THE SEQUENCES TO GO ALONG WITH THE QTY */
                /* (QUALIFIED BY SELECTION CRITERIA)           */
                for each rcsd_det where
                    rcsd_shipfrom   = rcs_shipfrom  and
                    rcsd_shipto     = rcs_shipto    and
                    rcsd_rlse_id    = rcs_rlse_id   and
                    rcsd_order      = so_nbr        and
                    rcsd_line       = sod_line
                                and
                    (rcsd_cust_job >= s_job and rcsd_cust_job <= s_job1)
                                and
                    (rcsd_cust_seq >= s_seq and rcsd_cust_seq <= s_seq1)
                                and
                    (rcsd_cust_ref >= s_ref and rcsd_cust_ref <= s_ref1)
                                and
                    (rcsd_dock >= s_dock and rcsd_dock <= s_dock1)
                                and
                    (rcsd_line_feed >= s_line_feed
                                        and rcsd_line_feed <= s_line_feed1)
                                and
                    (rcsd_status = s_status)
                                and
                    (not rcsd_picked)       and
                    (not rcsd_x_referenced) and
                    (not rcsd_delete)
                    use-index rcsd_index4:



                    /* DETERMINE SHIPPING DATE FROM SHIP/DELIVERY FLAG */

                    if rcs_date_type then

                        /* SHIP DATES */

                        assign
                            shipfrom_date = rcsd_date
                            shipfrom_time = rcsd_time.
                    else do:

                        /* SHIP DATES = DELIVERY DATES - TRANSIT LT*/

                        {gprun.i ""rcshipdt.p""
                        "(input rcsd_shipfrom, input rcsd_shipto,
                          input rcsd_date, input rcsd_time, input translt_days,
                          output shipfrom_date, output shipfrom_time,
                          output arrive_date, output arrive_time,
                          output ret_status)"}

                    end.  /* else do */


                    if (rcsd_discr_qty * sod_um_conv) <= qad_decfld[1]
                                    and
                        (shipfrom_date  > s_due_date     or
                        (shipfrom_date  = s_due_date and
                         shipfrom_time >= s_due_time))
                                    and
                        (shipfrom_date  < s_due_date1    or
                        (shipfrom_date  = s_due_date1 and
                         shipfrom_time <= s_due_time1))
                      then do:

                        /* CREATE A NEW rcsd_wrk RECORD.  */
                        /* COPY THE VALUES FROM qad_wkfl. */
                        create rcsd_wrk.
                        assign
                            wrk_shipfrom    = rcsd_shipfrom
                            wrk_shipto      = rcsd_shipto
                            wrk_rlse_id     = rcsd_rlse_id
                            wrk_cust_job    = rcsd_cust_job
                            wrk_cust_seq    = rcsd_cust_seq
                            wrk_part        = rcsd_part
                            wrk_date        = rcsd_date
                            wrk_time        = rcsd_time
                            wrk_cust_ref    = rcsd_cust_ref
                            wrk_qty         = rcsd_discr_qty
                            wrk_dock        = rcsd_dock
                            wrk_order       = rcsd_order
                            wrk_line        = rcsd_line
                            wrk_line_feed   = rcsd_line_feed
                            wrk_status      = rcsd_status
                            wrk_decfld[1]   = rcsd_discr_qty * sod_um_conv
                            wrk_decfld[2]   = qad_decfld[2]
                            wrk_decfld[3]   = qad_decfld[3]
                            wrk_charfld[1]  = qad_charfld[1]
                            wrk_charfld[2]  = qad_charfld[2]
                            wrk_charfld[3]  = qad_charfld[3]
                            wrk_charfld[4]  = qad_charfld[4]
                            wrk_charfld[5]  = qad_charfld[5]
                            wrk_charfld[6]  = qad_charfld[6]
                            wrk_charfld[7]  = qad_charfld[7]
                            wrk_charfld[8]  = qad_charfld[8]
                            wrk_charfld[9]  = qad_charfld[9]
                            wrk_charfld[10] = qad_charfld[10]
                            wrk_charfld[11] = qad_charfld[11]
                            wrk_charfld[12] = qad_charfld[12]
                            wrk_charfld[13] = qad_charfld[13]
                            wrk_charfld[14] = qad_charfld[14]
                            wrk_charfld[15] = qad_charfld[15]
                            wrk_rcsd_recid  = recid(rcsd_det).

                            if recid(rcsd_wrk) = -1 then .


                        /* REDUCE THE QTY IN THE ORIGINAL qad_wkfl */
                        qad_wkfl.qad_decfld[1]
                                        = qad_wkfl.qad_decfld[1]
                                        - (rcsd_discr_qty * sod_um_conv).

                        /* MARK SEQUENCE AS PICKED */
                        assign
                            rcsd_picked = yes
                            rcsd_mod_userid = global_userid
                            rcsd_mod_date = today
                            rcsd_mod_pgm = program-name(1).


                        if qad_wkfl.qad_decfld[1] = 0 then
                            leave.


                    end.  /* if rcsd_disc_qty >= qad_decfld[1] */
                    else
                        leave.

                end.  /* for each rcsd_det */


                /* DELETE qad_wkfl IF ALL QTYS HAVE BEEN MOVED */
                if qad_wkfl.qad_decfld[1] = 0 then
                    delete qad_wkfl.

            end.  /* if so_seq_order */

         end.  /* for each qad_wkfl */
